namespace Sop.Data;

public class PageModel<T>
{
    public PageModel()
    {
    }

    public PageModel(List<T> allList, int pageIndex, int pageSize)
    {
        pageIndex = pageIndex < 1 ? 1 : pageIndex;
        pageSize = pageSize < 1 ? 1 : pageSize;
        this.Total = (long) allList.Count;
        this.Items = allList.Skip<T>((pageIndex - 1) * pageSize).Take<T>(pageSize).ToList<T>();
        this.PageSize = (long) pageSize;
        this.PageIndex = (long) pageIndex;
        this.PageCount = this.Total > this.PageSize ? this.Total / (long) pageSize : 1L;
        if ((ulong) this.Total % (ulong) pageSize <= 0UL)
            return;
        ++this.PageCount;
    }

    public PageModel(IEnumerable<T> allList, int pageIndex, int pageSize)
    {
        List<T> list = allList.ToList<T>();
        this.Total = (long) list.Count;
        this.Items = list.Skip<T>((pageIndex - 1) * pageSize).Take<T>(pageSize).ToList<T>();
        this.PageSize = (long) pageSize;
        this.PageIndex = (long) pageIndex;
        this.PageCount = this.Total / (long) pageSize;
        if ((ulong) this.Total % (ulong) pageSize <= 0UL)
            return;
        ++this.PageCount;
    }

    public long Total { get; set; }

    public long PageIndex { get; set; }

    public long PageSize { get; set; }

    public long PageCount { get; set; }

    public List<T> Items { get; set; }
}